//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.zaicheng.cloud.remotecall;

import com.zaicheng.cloud.Client;
import com.zaicheng.cloud.netty.RpcRequest;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;

public interface Capability {
    static <E> E enrich(E componentToEnrich, List<Capability> capabilities) {
        return capabilities.stream().reduce(componentToEnrich, (component, capability) -> {
            return invoke(component, capability);
        }, (component, enrichedComponent) -> {
            return enrichedComponent;
        });
    }

    static <E> E invoke(E target, Capability capability) {
        return (E) Arrays.stream(capability.getClass().getMethods()).filter((method) -> {
            return method.getName().equals("enrich");
        }).filter((method) -> {
            return method.getReturnType().isInstance(target);
        }).findFirst().map((method) -> {
            try {
                return method.invoke(capability, target);
            } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException var4) {
                throw new RuntimeException("Unable to enrich " + target, var4);
            }
        }).orElse(target);
    }

    default Client enrich(Client client) {
        return client;
    }

//    default Retryer enrich(Retryer retryer) {
//        return retryer;
//    }

    default RequestInterceptor enrich(RequestInterceptor requestInterceptor) {
        return requestInterceptor;
    }

//    default Logger enrich(Logger logger) {
//        return logger;
//    }

//    default Level enrich(Level level) {
//        return level;
//    }

    default Contract enrich(Contract contract) {
        return contract;
    }

    default RpcRequest.Options enrich(RpcRequest.Options options) {
        return options;
    }

//    default Encoder enrich(Encoder encoder) {
//        return encoder;
//    }

//    default Decoder enrich(Decoder decoder) {
//        return decoder;
//    }

    default InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
        return invocationHandlerFactory;
    }

//    default QueryMapEncoder enrich(QueryMapEncoder queryMapEncoder) {
//        return queryMapEncoder;
//    }
}
